layui.use(['layer', 'form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;

    // 让当前iframe弹层高度适应
    admin.iframeAuto();

    $("#cronExpression").click(function () {
        var current = this;
        top.layui.admin.open({
            type: 2,
            area: ['700px','700px'],
            title: 'cron表达式生成器',
            content: Feng.ctxPath + '/sysJob/cron?cronExpression=' + this.value,
            success: function(layero, index){
                /*var body=top.layer.getChildFrame('body',index);//少了这个是不能从父页面向子页面传值的
                //获取子页面的元素，进行数据渲染
                body.contents().find("#cronVal").val(current.value);*/
                admin.putTempData('cron', current.value);
                admin.putTempData('cronIndex', index);
            },
            end: function () {
                var cron = admin.getTempData('cron');
                if( cron  != ''){
                    $("#cronExpression").val(cron);
                }
            }
        });
    });

    //初始化详情数据
        var ajax = new $ax(Feng.ctxPath + "/sysJob/view/" + Feng.getUrlParam("sysJobId"), function (data) {
            form.val('SysJobForm', data.data);
        }, function (data) {
            Feng.error("加载失败!" + data.responseJSON.message + "!");
        });
        ajax.start();

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/sysJob/edit", function (data) {
            Feng.success("修改成功!");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("修改失败!" + data.responseJSON.message + "!");
        });
        ajax.set(data.field);
        ajax.start();
    });
});